/**
 * 所有跟用户相关的接口
 */

import { ApiResponse } from '@/@types/http';
import axios from './axios';

/**
 * @interface loginParams -登录参数
 * @property {string} code -验证码
 * @property {string} username -用户名
 * @property {string} password -用户密码
 * @property {string} mobile -手机号
 */
interface LoginParams {
  code: string;
  username: string;
  password: string;
  mobile: string;
}

/**
 * @interface SendPhoneCodeParams -获取验证码参数
 */
interface SendPhoneCodeParams {
  mobile: string | number;
}

/**
 * 用户相关接口
 */
class UserService {
  // 用户名密码登录
  static async login<T>(data: LoginParams) {
    return axios<ApiResponse<T>>({
      url: '/auth-api/v1/auth2',
      method: 'post',
      data,
    });
  }

  static logout<T = any>(id: number) {
    return axios<ApiResponse<T>>({
      url: `/auth-api/v1/logout`,
      method: 'post',
      data: { id },
    });
  }

  /**
   * 验证码登录
   * @param data
   * @returns
   */
  static async loginBySyscode<T>(data: LoginParams) {
    return axios<ApiResponse<T>>({
      url: '/auth-api/v1/auth',
      method: 'post',
      data,
    });
  }

  // 获取用户信息
  static getUserDetail<T>() {
    return axios<ApiResponse<T>>({
      url: '/saas-api/v1/me',
      method: 'get',
    });
  }

  // 发送手机验证码
  static sendPhoneCode<T = any>(params: SendPhoneCodeParams) {
    return axios<ApiResponse<T>>({
      url: '/auth-api/v1/code',
      method: 'get',
      params,
    });
  }

  static register2<T>(data: any) {
    return axios<ApiResponse<T>>({
      url: `/saas-api/v1/updateCompany`,
      method: 'post',
      data,
    });
  }

  // 注册第三步，绑定招聘专家
  static register3<T>(data: {
    companyId: number;
    adviserId?: number;
    reason?: string;
  }) {
    return axios<ApiResponse<T>>({
      url: `/saas-api/v1/bindCompanyAdviser`,
      method: 'post',
      data,
    });
  }

  // 修改密码
  static changePwd<T>(params: {
    newPwd: string | number;
    oldPwd?: string | number;
  }) {
    return axios<ApiResponse<T>>({
      url: `/saas-api/v1/updatePwd`,
      method: 'post',
      data: params,
    });
  }
}

export default UserService;
